/*
 * Copyright (c) 2008-2012
 * LANIT
 * All rights reserved.
 *
 * This product and related documentation are protected by copyright and
 * distributed under licenses restricting its use, copying, distribution, and
 * decompilation. No part of this product or related documentation may be
 * reproduced in any form by any means without prior written authorization of
 * LANIT and its licensors, if any.
 *
 * $Id$
 */

import java.sql.*;

/**
 * todo Document type DataBaseWork
 */
public class DataBaseWork {

    public void connectToDB() throws SQLException, ClassNotFoundException {

        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.75.161:1521:orclpega", "pega", "pega");
        int rs;

        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM lanitbpm_timesheetreports");
        while (resultSet.next()){
            Println.toOut(resultSet.getString(1));
        }
        //DELETE ROW
        /*rs = statement.executeUpdate("DELETE FROM lanitbpm_timesheetreports WHERE ID = 2");
        Println.toOut(Integer.toString(rs));*/
        //Insert ROW
        /*rs = statement.executeUpdate("INSERT INTO lanitbpm_timesheetreports(ID,pzinskey) values (1,2622652)");
        Println.toOut(Integer.toString(rs));*/

        PreparedStatement preparedStatement =  connection.prepareStatement("SELECT hours FROM lanitbpm_timesheetreports where id = ?");
        preparedStatement.setString(1, "5");

        resultSet = preparedStatement.executeQuery();
        /*resultSet.next();
        Println.toOut(resultSet.getString(1));*/
        while (resultSet.next()){
                    Println.toOut(resultSet.getString(1));
                }
        resultSet.close();
        preparedStatement.close();
        connection.close();

    }
}
